<?php
use yii\bootstrap\ActiveForm;
?>
<link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="../static/plugins/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<link rel="stylesheet" href="../static/jBox/Skins/Metro/jbox.css" type="text/css">
<link rel="stylesheet" href="../static/dist/css/AdminLTE.min.css" type="text/css">
<link rel="stylesheet" href="../static/css/admin.css" type="text/css">
<link rel="stylesheet" href="../static/plugins/treeTable/jquery.treetable.css" type="text/css">
<link rel="stylesheet" href="../static/plugins/treeTable/jquery.treetable.theme.default.css" type="text/css">

<style>
    .ul_tree_display{
        display: none;
    }
    .tr_tree_display{
        display: none;
    }
    .table>tbody>tr>td{
        vertical-align: middle;
        font-size: 0.8em;
    }
</style>
<div class="tabs-panel">

    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <button type="button" class="btn btn-block btn-success depart-modal" style="width: 100px;">添加组织</button>
                    <!--<h3 class="box-title">Hover Data Table</h3>-->
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <table id="example2" class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="depart_table_th">部门名称</th>
                            <th class="depart_table_th">修改</th>
                            <th class="depart_table_th">启用</th>
                            <th class="depart_table_th">添加子部门</th>
                            <th class="depart_table_th">删除</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($data_list as $key => $val) {?>
                            <tr data-tt-id="<?= $val['id']?>" data-use-flg="<?=(intval($val['use_flg']) == 1 ? 0 : 1)?>" data-tt-parent-id="<?= $val['parent_id']?>" class="">
                                <td style="width: 500px;">
                                    <?= $val['html']?>
                                    <input class="depart-input" style="width: 150px" name="dept_name_<?= $val['id']?>" value="<?= $val['dept_name']?>" placeholder="部门名称"/> &nbsp;
                                    排序&nbsp;<input style="width: 50px" name="sort_<?= $val['id']?>" class="depart-input" placeholder="排序" value="<?= $val['sort']?>"/>
                                </td>
                                <td class="depart_table_td" style="width: 100px;"><a href="javascript:;" onclick="updateDepart(<?= $val['id']?>)">修改</a></td>
                                <td class="depart_table_td" style="width: 100px;">
                                    <?php //if($val['use_flg'] == 1){?>

                                        <!-- <a href="javascript:;" onclick="disableClick(<?= $val['id']?>)">禁用</a>

                                    <?php //}else{?>

                                        <a href="javascript:;" onclick="enableClick(<?= $val['id']?>)">启用</a> -->

                                    <?php //}?>
                                    <input style="width:20px;height:20px;" <?=($val['use_flg'] == 1 ? 'checked' : '')?> class="input-check" type="checkbox">
                                </td>
                                <td class="depart_table_td" style="width: 100px;"><a href="javascript:;" onclick="addDepart(<?= $val['id']?>)">添加</a></td>
                                <td class="depart_table_td" style="width: 100px;"><a href="javascript:;" onclick="delDepart(<?= $val['id']?>)">X</td>
                            </tr>
                        <?php } ?>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>

    </div>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        部门添加
                    </h4>
                </div>
                <div class="modal-body">
                    <?php $form = ActiveForm::begin([
                        'id'     => 'depart_form',
                        'action' => ['/sys-department/add-depart']
                    ]); ?>
                    <!--<form action="/setting/add-depart" method="post" id="depart_form">-->
                    <div class="box-body">
                        <div class="form-group">
                            <label for="exampleInputEmail1">部门名称</label>
                            <input type="text" class="form-control" name="dept_name" id="dept_name" placeholder="部门名称">
                        </div>
                        <div class="form-group">
                            <label for="exampleInputPassword1">排序</label>
                            <input type="text" style="width: 50%;" name="sort" class="form-control" id="sort" placeholder="排序">
                        </div>
                        <div class="form-group">
                            <label for="exampleInputPassword1">选择上级部门</label>
                            <input type="text" style="width: 50%;" class="form-control" id="depart_name" value="顶级部门" readonly="readonly">
                            <input type="hidden" name="parent_id" id="parent_id" value="0">
                            <ul id="treeDemo" class="ztree ul_tree_display"></ul>
                        </div>

                        <div class="form-group">
                            <label for="exampleInputEmail1">状态</label>
                            <select id="use_flg" name="use_flg" class="form-control" style="width: 50%;">
                                <option value="1">启用</option>
                                <option value="0">禁用</option>
                            </select>
                        </div>

                        <div class="form-group">
                            <label for="exampleInputPassword1">备注</label>
                            <textarea class="form-control" name="memo" id="memo" rows="3" placeholder="" ></textarea>
                        </div>
                    </div>
                    <!-- /.box-body -->

                    <?php ActiveForm::end(); ?>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <a type="button" class="btn btn-primary ajax_post_depart">
                        提交
                    </a>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>
<!-- 固定js -->
<script type="text/javascript" src="../static/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script type="text/javascript" src="../static/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../static/plugins/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../static/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../static/jBox/jquery.jBox-2.3.min.js"></script>
<script type="text/javascript" src="../static/jBox/i18n/jquery.jBox-zh-CN.js"></script>
<script type="text/javascript" src="../static/plugins/treeTable/jquery.treetable.js"></script>
<script type="text/javascript" src="../static/plugins/zTree/js/jquery.ztree.core.js"></script>
<!-- 自定义js -->
<script type="text/javascript" src="/static/app/global.js?version=<?=Yii::$app->params['version']?>"></script>
<script type="text/javascript" src="../static/app/sys-department/index.js?version=<?=Yii::$app->params['version']?>"></script>
<script type="text/javascript">
    var zNodes = <?= $tree_list ?>;
</script>